const http = require('../../utils/http.js'); //相对路径
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navindex: 0,
    list: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getData('',1,1);
  },
  // 顶部状态切换
  navbind(e) {
    let index = e.currentTarget.dataset.index;
    let list = this.data.list;
    list.data = [];
    this.setData({
      navindex: index,
      list: list
    })
    this.getData('',index+1,1);
  },
  searchorder_list(e) {
    let list = this.data.list;
    list.data = [];
    this.setData({
      list: list
    })
    this.getData(e.detail.value,this.data.navindex+1,1);
  },
  // 进入详情页
  gopage(e) {
    wx.navigateTo({
      url: '/pages/classify/child/detail?id=' + e.currentTarget.dataset.id
    })
  },
  // 获取数据
  getData(search,appointment_status,page) {
    http.postRequest('/mini/v1/appointment/order_list',{search: search, appointment_status: appointment_status, page: page}, res=> {
      let list = this.data.list;
      if(!list.data) {
        for(let i in res.data.data) {
          res.data.data[i].time1 = http.transTime(res.data.data[i].start_time);
          res.data.data[i].time2 = http.transTime(res.data.data[i].end_time);
        }
        list = res.data
      } else {
        for(let i in res.data.data) {
          res.data.data[i].time1 = http.transTime(res.data.data[i].start_time);
          res.data.data[i].time2 = http.transTime(res.data.data[i].end_time);
          list.data.push(res.data.data[i]);
        }
      }
      this.setData({
        list: list
      })
    }) 
  }
})